package com.thinkingcoder.tccache.core.command.list;

import static com.thinkingcoder.tccache.constant.CommandConstants.ListCmd.LINDEX;

import com.thinkingcoder.tccache.core.command.Command;
import com.thinkingcoder.tccache.core.model.Reply;
import com.thinkingcoder.tccache.core.TcCache;

/**
 * LINDEX command.
 */
public class LIndexCmd implements Command {
    @Override
    public String name() {
        return LINDEX;
    }

    @Override
    public Reply<?> exec(TcCache cache, String[] args) {
        String key = getKey(args);
        int index = Integer.parseInt(getValue(args));
        return Reply.bulkString(cache.lIndex(key, index));
    }
}
